package logic

import (
	"context"
	"novel-start/novelrpc/novelrpc"

	"novel-start/api/internal/svc"
	"novel-start/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewNovelAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelAddLogic {
	return &NovelAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *NovelAddLogic) NovelAdd(req *types.NovelAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	date, err := l.svcCtx.NovelRpc.NovelAdd(l.ctx, &novelrpc.NovelAddRequest{
		UserId:    req.UserId,
		Title:     req.Title,
		Type:      req.Type,
		NovelDesc: req.NovelDesc,
		NovelUrl:  req.NovelUrl,
		NovelNum:  req.NovelNum,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Date:    nil,
		}, nil
	}

	return &types.Response{
		Message: "小说添加成功",
		Code:    200,
		Date:    date,
	}, nil
}
